<?php
namespace app\common\model;
use think\Config;
use think\Model;

class Admin extends Model{

    protected $table = "jiujiu_admin";

    public function checkUser($account,$password){
        $userPassword = Config::get('userPassword');
        $password = md5($userPassword['prefix'].trim($password).$userPassword['suffix']);
        $account = trim($account);
        $user = $this->where('name',$account)->where('password',$password)->find();
        if($user){
            return $user;
        }

    }

    public function changePwd($uid,$pwd){
        $userPassword = Config::get('userPassword');
        $password = md5($userPassword['prefix'].trim($pwd).$userPassword['suffix']);
        $this->where('id',$uid)->update([
            'password'=>$password
        ]);

    }


    public function saveAdmin($data,$img=''){
        if($img){
            $data['img'] = upload($img);
        }
        if(isset($data['password']) && trim($data['password'])){
            $userPassword = Config::get('userPassword');
            $data['password'] = md5($userPassword['prefix'].trim($data['password']).$userPassword['suffix']);
        }

        if(isset($data['id'])&&$data['id']){
            $this->where('id',$data['id'])->update($data);
        }
        else{
            $data['addtime'] = time();
            $this->insert($data);
        }
    }









}